package com.tengfei.blogsystem.controller.admin;

/**
 * @version v1.0
 * @author} feige
 * @date 2021-10-15-16:22
 * @description
 */

import com.tengfei.blogsystem.pojo.Looper;
import com.tengfei.blogsystem.response.ResponseResult;
import com.tengfei.blogsystem.service.ILopperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图api
 */
@PreAuthorize("@permission.admin()")    //需要管理员权限
@RestController
@RequestMapping("/admin/looper")
public class LooperAdminApi {

    @Autowired
    private ILopperService lopperService;

    /**
     * 获取轮播图列表
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{page}/{size}")
    public ResponseResult listLooper(@PathVariable("page") int page, @PathVariable("size") int size) {
        return lopperService.listLooper(page, size);
    }

    /**
     * 添加轮播图
     *
     * @param looper
     * @return
     */
    @PostMapping("/")
    public ResponseResult addLooper(@RequestBody Looper looper) {
        return lopperService.addLooper(looper);
    }

    /**
     * 删除轮播图
     *
     * @param looperId
     * @return
     */
    @DeleteMapping("/{looperId}")
    public ResponseResult deleteLooper(@PathVariable("looperId") String looperId) {
        return lopperService.deleteLooper(looperId);
    }

    /**
     * 修改轮播图
     *
     * @param looperId
     * @param looper
     * @return
     */
    @PutMapping("/{looperId}")
    public ResponseResult updateLooper(@PathVariable("looperId") String looperId, @RequestBody Looper looper) {
        return lopperService.updateLooper(looperId, looper);
    }

    /**
     * 查找轮播图
     *
     * @param looperId
     * @return
     */
    @GetMapping("/{looperId}")
    public ResponseResult getLooper(@PathVariable("looperId") String looperId) {
        return lopperService.getLooper(looperId);
    }
}
